import { FormSchema } from '/@/components/Form';
import { BasicColumn } from '/@/components/Table/src/types/table';
import { FormProps } from '/@/components/Table';
import { getDocLabelApi } from '/@/api/demo/flow';
import { getDocBrowserUseType } from '/@/api/demo/knowledge';
import { useI18n } from '/@/hooks/web/useI18n';

const { t } = useI18n();
// 知识库高级搜索
export function getKnowledgeSearch(): FormSchema[] {
  return [
    {
      field: 'Name',
      component: 'Input',
      label: t('routes.demo.documentManager.advancedSearchForm.name'),
      componentProps: {
        placeholder: t('routes.demo.documentManager.advancedSearchForm.namePlaceholder'),
      },
      colProps: {
        xl: 12,
        xxl: 12,
      },
    },
    {
      field: 'ThitObjectId',
      component: 'Input',
      label: t('routes.demo.documentManager.advancedSearchForm.code'),
      componentProps: {
        placeholder: t('routes.demo.documentManager.advancedSearchForm.codePlaceholder'),
      },
      colProps: {
        xl: 12,
        xxl: 12,
      },
    },
    {
      field: 'FileName',
      component: 'Input',
      label: t('routes.demo.documentManager.advancedSearchForm.fileName'),
      componentProps: {
        placeholder: t('routes.demo.documentManager.advancedSearchForm.fileNamePlaceholder'),
      },
      colProps: {
        xl: 12,
        xxl: 12,
      },
    },
    {
      field: 'DocLabel',
      component: 'ApiTreeSelect',
      label: t('routes.demo.documentManager.advancedSearchForm.tag'),
      componentProps: {
        api: getDocLabelApi,
        placeholder: t('routes.demo.documentManager.advancedSearchForm.tagPlaceholder'),
        replaceFields: {
          key: 'labelID',
          value: 'labelID',
          title: 'labelName',
          children: 'sonlabellist',
        },
      },
      colProps: {
        xl: 12,
        xxl: 12,
      },
    },
    {
      field: 'FileType',
      component: 'ApiSelect',
      label: t('routes.demo.documentManager.advancedSearchForm.fileType'),
      componentProps: {
        placeholder: t('routes.demo.documentManager.advancedSearchForm.fileTypePlaceholder'),
        api: getDocBrowserUseType,
        labelField: 'fileTypeStr',
        valueField: 'fileType',
      },
      colProps: {
        xl: 12,
        xxl: 12,
      },
    },
    {
      field: 'releaseTime',
      component: 'RangePicker',
      label: t('routes.demo.documentManager.advancedSearchForm.publishTime'),
      colProps: {
        xl: 12,
        xxl: 12,
      },
    },
  ];
}

// 知识库表格搜索
export function getKnowledgeColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.documentManager.knowledgeBase.name'),
      dataIndex: 'name',
      fixed: 'left',
      align: 'left',
      width: 300,
    },
    {
      title: t('routes.demo.documentManager.knowledgeBase.code'),
      dataIndex: 'thitObjectId',
      align: 'left',
      width: 200,
    },
    {
      title: t('routes.demo.documentManager.knowledgeBase.currentHolder'),
      dataIndex: 'holder',
      width: 120,
    },
    {
      title: t('routes.demo.documentManager.knowledgeBase.fileType'),
      dataIndex: 'docType',
      width: 100,
    },
    {
      title: t('routes.demo.documentManager.knowledgeBase.currentVersion'),
      dataIndex: 'canBrowserVision',
      width: 200,
    },
    {
      title: t('routes.demo.documentManager.knowledgeBase.highestVersion'),
      dataIndex: 'curreVision',
      width: 100,
    },
    {
      title: t('routes.demo.documentManager.knowledgeBase.remark'),
      dataIndex: 'remark',
      width: 100,
    },
    {
      title: t('routes.demo.documentManager.knowledgeBase.createTime'),
      dataIndex: 'createTime',
      width: 150,
      slots: { customRender: 'createTime' },
    },
    {
      title: t('routes.demo.documentManager.knowledgeBase.lastModifiedTime'),
      dataIndex: 'lastModifyTime',
      width: 150,
      slots: { customRender: 'lastModifyTime' },
    },
    {
      title: t('routes.demo.documentManager.knowledgeBase.status'),
      dataIndex: 'status',
      width: 100,
    },
    {
      title: t('routes.demo.documentManager.knowledgeBase.fileName'),
      dataIndex: 'fileName',
      width: 300,
    },
    {
      title: t('routes.demo.documentManager.knowledgeBase.customPropertySet'),
      dataIndex: 'allCustomProp',
      width: 200,
    },
    {
      title: t('routes.demo.documentManager.knowledgeBase.tagName'),
      dataIndex: 'labelNameList',
      width: 200,
    },
  ];
}

// 知识库添加属性
export function getAddKeyWordOrLabel(): FormSchema[] {
  return [
    {
      field: 'labelName',
      component: 'TreeSelect',
      label: '标签',
      componentProps: {
        placeholder: '请输入标签',
        treeData: [
          {
            title: 'Node1',
            value: '0-0',
            key: '0-0',
            children: [
              {
                title: 'Child Node1',
                value: '0-0-0',
                key: '0-0-0',
              },
            ],
          },
          {
            title: 'Node2',
            value: '0-1',
            key: '0-1',
            children: [
              {
                title: 'Child Node3',
                value: '0-1-0',
                key: '0-1-0',
              },
              {
                title: 'Child Node4',
                value: '0-1-1',
                key: '0-1-1',
              },
              {
                title: 'Child Node5',
                value: '0-1-2',
                key: '0-1-2',
              },
            ],
          },
        ],
      },
    },
    {
      field: 'keyWord',
      component: 'Input',
      label: '关键字',
      componentProps: {
        placeholder: '关键字',
      },
    },
  ];
}

// 标签管理表格
export function getLabelColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.knowledgeManager.labelManagerSet.name'),
      dataIndex: 'labelName',
      fixed: 'left',
      align: 'left',
      width: 300,
    },
    {
      title: t('routes.demo.knowledgeManager.labelManagerSet.status'),
      dataIndex: 'status',
      width: 100,
      slots: { customRender: 'status' },
    },
    {
      title: t('routes.demo.knowledgeManager.labelManagerSet.key'),
      dataIndex: 'keyValues',
      width: 100,
    },
    {
      title: t('routes.demo.knowledgeManager.labelManagerSet.sort'),
      dataIndex: 'orders',
      width: 100,
    },
    {
      title: t('routes.demo.knowledgeManager.labelManagerSet.remark'),
      dataIndex: 'remark',
      width: 100,
    },
  ];
}

// 标签管理表格搜索
export function getLabelFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 100,
    autoSubmitOnEnter: true,
    colon: false, // 是否显示冒号
    schemas: [
      {
        field: `labelName`,
        label: t('routes.demo.knowledgeManager.labelManagerSet.name'),
        component: 'Input',
        colProps: {
          xl: 12,
          xxl: 8,
        },
        componentProps: {
          placeholder: t('routes.demo.knowledgeManager.labelManagerSet.namePlaceholder'),
        },
      },
      {
        field: `status`,
        label: t('routes.demo.knowledgeManager.labelManagerSet.status'),
        component: 'Select',
        colProps: {
          xl: 12,
          xxl: 8,
        },
        componentProps: {
          placeholder: t('routes.demo.knowledgeManager.labelManagerSet.statusPlaceholder'),
          options: [
            {
              value: '0',
              label: t('routes.demo.knowledgeManager.labelManagerSet.open'),
            },
            {
              value: '1',
              label: t('routes.demo.knowledgeManager.labelManagerSet.close'),
            },
          ],
        },
      },
    ],
  };
}

// 标签管理添加标签
export function getAddLabel(): FormSchema[] {
  return [
    {
      field: 'labelName',
      component: 'Input',
      label: t('routes.demo.knowledgeManager.labelManagerSet.name'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.knowledgeManager.labelManagerSet.namePlaceholder'),
      },
    },
    {
      field: 'keyValues',
      component: 'Input',
      label: t('routes.demo.knowledgeManager.labelManagerSet.key'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.knowledgeManager.labelManagerSet.keyPlaceholder'),
      },
    },
    {
      field: 'orders',
      component: 'InputNumber',
      label: t('routes.demo.knowledgeManager.labelManagerSet.sort'),
      required: true,
      componentProps: {
        min: 1,
        placeholder: t('routes.demo.knowledgeManager.labelManagerSet.sortPlaceholder'),
      },
    },
    {
      field: 'status',
      component: 'Select',
      label: t('routes.demo.knowledgeManager.labelManagerSet.status'),
      required: true,
      componentProps: {
        placeholder: t('routes.demo.knowledgeManager.labelManagerSet.statusPlaceholder'),
        options: [
          {
            value: '0',
            label: t('routes.demo.knowledgeManager.labelManagerSet.open'),
          },
          {
            value: '1',
            label: t('routes.demo.knowledgeManager.labelManagerSet.close'),
          },
        ],
      },
    },
    {
      field: 'remark',
      component: 'InputTextArea',
      label: t('routes.demo.knowledgeManager.labelManagerSet.remark'),
      componentProps: {
        placeholder: t('routes.demo.knowledgeManager.labelManagerSet.remarkPlaceholder'),
      },
    },
  ];
}

// 获取用户历史借阅审批流程数据表格
export function getHistoryApprovalProcessColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.knowledgeManager.viewHistorySet.templateId'),
      dataIndex: 'workflow',
      fixed: 'left',
      align: 'left',
      width: 200,
    },
    {
      title: t('routes.demo.knowledgeManager.viewHistorySet.name'),
      dataIndex: 'name',
      width: 100,
    },
    {
      title: t('routes.demo.knowledgeManager.viewHistorySet.createTime'),
      dataIndex: 'createTime',
      width: 150,
      slots: { customRender: 'createTime' },
    },
    {
      title: t('routes.demo.knowledgeManager.viewHistorySet.endTime'),
      dataIndex: 'endtime',
      width: 150,
      slots: { customRender: 'endtime' },
    },
    {
      title: t('routes.demo.knowledgeManager.viewHistorySet.principal'),
      dataIndex: 'actor',
      width: 100,
    },
    {
      title: t('routes.demo.knowledgeManager.viewHistorySet.creator'),
      dataIndex: 'creator',
      width: 100,
    },
    {
      title: t('routes.demo.knowledgeManager.viewHistorySet.remark'),
      dataIndex: 'remake',
      width: 100,
    },
  ];
}

// 历史借阅南批流程下挂文件表格
export function getHistoryApprovalProcessFileColumns(): BasicColumn[] {
  return [
    {
      title: t('routes.demo.knowledgeManager.viewHistorySet.fileName'),
      dataIndex: 'name',
      fixed: 'left',
      align: 'left',
      width: 200,
    },
    {
      title: t('routes.demo.knowledgeManager.viewHistorySet.fileType'),
      dataIndex: 'type',
      width: 100,
    },
    {
      title: t('routes.demo.knowledgeManager.viewHistorySet.createTime'),
      dataIndex: 'createTime',
      width: 100,
      slots: { customRender: 'createTime' },
    },
    {
      title: t('routes.demo.knowledgeManager.viewHistorySet.version'),
      dataIndex: 'version',
      width: 100,
    },
  ];
}
